/*
 * ESP32 Bluetooth Audio Receiver - Bluetooth Audio Receiver Header
 *
 * Developed based on ESP-IDF framework using Espressif official interfaces
 * Core bluetooth processing, audio data callbacks and other components are original development
 *
 * Copyright (c) 2025 lianggumei
 *
 * SPDX-License-Identifier: MIT
 */

#ifndef __BLUETOOTH_AUDIO_RECEIVER_HPP__
#define __BLUETOOTH_AUDIO_RECEIVER_HPP__

#include <cstdint>
#include <memory>

#include "audio_processor.hpp"
#include "esp_a2dp_api.h"
#include "esp_avrc_api.h"
#include "esp_bt.h"
#include "esp_bt_main.h"
#include "esp_gap_bt_api.h"
#include "esp_log.h"

class BluetoothAudioReceiver {
 public:
  BluetoothAudioReceiver();
  ~BluetoothAudioReceiver();

  // Initialize bluetooth audio receiver
  esp_err_t Initialize();

  // Start bluetooth audio receiver
  esp_err_t Start();

  // Set audio processor
  void SetAudioProcessor(std::shared_ptr<AudioProcessor> processor);

 private:
  // Bluetooth callback functions
  static void GapCallback(esp_bt_gap_cb_event_t event, esp_bt_gap_cb_param_t* param);
  static void A2dpCallback(esp_a2d_cb_event_t event, esp_a2d_cb_param_t* param);
  static void AvrcControllerCallback(esp_avrc_ct_cb_event_t event, esp_avrc_ct_cb_param_t* param);
  static void AvrcTargetCallback(esp_avrc_tg_cb_event_t event, esp_avrc_tg_cb_param_t* param);
  static void AudioDataCallback(const uint8_t* data, uint32_t len);

  // Volume control
  static void VolumeSetByController(uint8_t volume);

  std::shared_ptr<AudioProcessor> audio_processor_;
  static BluetoothAudioReceiver* instance_;

  static const char* kTag;
  static const char* kDeviceName;
  static uint8_t s_volume_;
};

#endif /* __BLUETOOTH_AUDIO_RECEIVER_HPP__ */
